<!--
* description: 总部周计划制定
* author: wangml
* createdDate: 2020-12-01
-->

<template>
  <div class="app-container app-container-table">
    <!-- 单表格模版页面 -->
    <one-table-template
      ref="multipleTable"
      :supplement="supplement"
      :position-span="positionSpan"
      :dynamic-api-config="dynamicApiConfig"
      :dynamic-buttons="dynamicButtons"
      :dynamic-components="tableComponents"
      :dynamic-table-cols="dynamicTableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-more-btn="true"
      :dynamic-is-show-select="true"
      :dynamic-api-style="apiStyle"
      :showbtn-length="4"
      :dynamic-page-size="10"
      :page-size-array="newpagesizeArr"
      :refresh-table-key="refreshTableKey"
      :callback-obj="callbackObj"
      @hiddenColData="hiddenColData"
    >
      <!--      <template v-slot:childTable="{ row }">-->
      <!--        <mix-table-->
      <!--          :list-data="codeList[row.index]"-->
      <!--          :table-height="260"-->
      <!--          :highlight-current-row="true"-->
      <!--          :dynamic-table-cols="tableCols"-->
      <!--        />-->
      <!--      </template>-->
    </one-table-template>
    <p style="position:absolute;right:85px;bottom:-3px;color:red">当前总计划数量：{{ totalnum }}台</p>
    <edit
      :title="editTitle"
      :popups-visible="showdia"
      :edit-forms="editForms"
      :edit-width="editWidth"
      :dynamic-edit-row-data="rowData"
      popups-state="edit"
      @close="close1"
    />
    <sales-creation
      ref="carType"
      :popups-visible.sync="curPopupsVisible"
      :dialog-status="dialogStatus"
      :dynamic-edit-row-data="rowData"
      :popups-state="popstate"
    />
    <is-jinji
      :key="switchPopupsKey"
      :popups-visible="switchPopupsVisible"
      @sendsave="sendsave"
      @close="autoClose"
    />
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import Vue from 'vue'
import api from '@/api/planReport'
import salesCreation from '../makeSalesPlan/salesCreation1'
import edit from './edit1'
import isJinji from './isJinji'
import { exportExcel } from '@/utils/getTimeString'
import { orgApis } from '@/api/vesalesapi'
import commData from '../common/index.js'

export default {
  name: 'ConfirmWeekSalesPlan',
  components: {
    OneTableTemplate,
    edit,
    isJinji,
    salesCreation
  },
  mixins: [oneTableWithViewTemplateMixins],
  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData(
      // 同时加载当前页面和编辑框页面的配置
      [to.path, ''],
      function() {
        next()
      })
  },
  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path
    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])
    return {
      totalnum: 0,
      newpagesizeArr: ['10', '50', '100', '500', '1000', '2000'],
      supplement: {
        supplements: '请在导入前确认模板字段格式是否正确，例如年份：20xx,月份：1~12,周度：1~52',
        IsSupplement: true,
        span: 8
      },
      positionSpan: [8, 8],
      dialogStatus: 'weekPlan',
      curPopupsVisible: false,
      switchPopupsVisible: false,
      switchPopupsKey: '',
      popstate: 'add',
      showdia: false,
      rowData: {},
      codeList: [],
      listData: [],
      editTitle: '总部周计划确认',
      editWidth: '45%',
      editForms: [
        {
          // title: '保险费发票',
          tid: 1,
          data: [
            {
              compKey: 'carSeries',
              labelName: '车系名称：',
              codeField: 'carSeriesId',
              textField: 'carSeriesCn',
              oFields: 'carSeriesId,carSeriesCn',
              customObj: { api: orgApis.listOfCarSeries, selectType: '1' },
              component: () => import('@/components/org/commonSelect'),
              isMust: true,
              isRequire: true
            },
            {
              compKey: 'carConfig',
              labelName: '基础车型名称：',
              codeField: 'carConfigId',
              textField: 'carConfigCn',
              disabled: true,
              component: () => import('@/components/org/commonSelect'),
              oFields: 'carConfigId,carConfigCn',
              parentFileds: 'value:carSeriesId,disabled:carSeriesId-carConfigId--false',
              customObj: {
                listQuery: { carSeriesId: '' },
                api: orgApis.listOfCarModel, selectType: '1'
              },
              isMust: true,
              isRequire: true
            },
            {
              compKey: 'optionalPag',
              labelName: '选装包：',
              codeField: 'optionalPagId',
              textField: 'optionalPagName',
              disabled: true,
              component: () => import('@/components/org/commonSelect'),
              parentFileds: 'value:carConfigId|carSeriesId,disabled:carConfigId-optionalPagId--false',
              oFields: 'optionalPagId,optionalPagName',
              customObj: {
                listQuery: {
                  carConfigId: '', carSeriesId: ''
                },
                api: orgApis.listOfPackage, selectType: '1'
              },
              type: 'dropdownList',
              isMust: true,
              isRequire: true
            },
            {
              compKey: 'carColor',
              labelName: '车身颜色：',
              codeField: 'carColorId',
              textField: 'carColorName',
              disabled: true,
              component: () => import('@/components/org/commonSelect'),
              parentFileds: 'value:carConfigId|carSeriesId|optionalPagId,disabled:optionalPagId-carColorId--false',
              oFields: 'carColorId,carColorName',
              customObj: {
                listQuery: {
                  carConfigId: '', carSeriesId: '', optionalPagId: ''
                },
                api: orgApis.listOfCarColor, selectType: '1'
              },
              type: 'dropdownList',
              isMust: true,
              isRequire: true
            },
            {
              compKey: 'carIncolor',
              labelName: '内饰颜色：',
              codeField: 'carIncolorId',
              textField: 'carIncolorName',
              disabled: true,
              component: () => import('@/components/org/commonSelect'),
              parentFileds: 'value:carConfigId|carSeriesId|optionalPagId,disabled:optionalPagId-carIncolorId--false',
              oFields: 'carIncolorId,carIncolorName',
              customObj: {
                listQuery: {
                  carConfigId: '', carSeriesId: '', optionalPagId: ''
                },
                api: orgApis.listOfCarInterior, selectType: '1'
              },
              type: 'dropdownList',
              isMust: true,
              isRequire: true
            },
            {
              compKey: 'compKey2',
              labelName: '车型选配器：',
              codeField: 'ttCode',
              disabled: true,
              component: () => import('@/components/org/commonInput'),
              type: 'dropdownList',
              isMust: true,
              isRequire: true
            },
            {
              compKey: 'compKey3',
              labelName: '计划月份：',
              codeField: 'planMonth',
              component: () => import('@/components/org/datePicker/datePicker.vue'),
              dateType: 'month',
              dateOptionsType: '3',
              disabled: true,
              type: 'dropdownList',
              isMust: true,
              isRequire: true
            },
            {
              compKey: 'compKey4',
              labelName: '计划周度：',
              codeField: 'planWeek',
              component: () => import('@/components/org/commonInput'),
              disabled: true,
              isMust: true,
              isRequire: true
            },
            {
              compKey: 'compKey5',
              labelName: '数量：',
              codeField: 'planNum',
              component: () => import('@/components/org/commonInput'),
              isMust: true,
              validrule: {
                isInteger: true
              },
              isRequire: true
            }
          ]
        }
      ],
      genCodeFiled: null,
      selectList: '',
      list: '',
      idList: [],
      clickRowsData: {},
      // 指定请求类型 可以统一在 utils/config.js中配置
      apiStyle: 'restful',
      dynamicApiConfig: api.confirmWeekPlanQuery,
      refreshTableKey: '0',
      ruleSettingShow: false,
      // table表格查询API配置对象
      // 动态组件-查询条件
      tableComponents:
          this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].tableComponents.length > 0
            ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode].tableComponents
            : [
              ...commData.ModelOptions(2),
              {
                compKey: 'comKey7',
                labelName: '计划月份：',
                codeField: 'planMonth',
                component: () => import('@/components/org/datePicker/datePicker.vue'),
                dateType: 'month',
                format: 'yyyy-MM',
                // dateOptionsType: '3',
                isMust: false,
                span: 6
              },
              {
                compKey: 'comKey8',
                labelName: '计划周度：',
                codeField: 'planWeek',
                isMul: true,
                oFields: 'planWeek,planWeekText',
                component: () => import('@/components/org/commonSelect'),
                type: 'dropdownList',
                options: [],
                isMust: false,
                span: 6
              },
              {
                compKey: 'comKey9',
                labelName: '计划状态：',
                codeField: 'planStatus',
                isMul: true,
                // lookuptype: 'VE1112',
                component: () => import('@/components/org/commonSelect'),
                customObj: { listQuery: { lookupTypeCode: 'VE1112', attribute2: '1' }},
                type: 'dropdownList',
                isMust: false,
                span: 6
              },
              {
                compKey: 'compKey10',
                labelName: '制作时间：',
                codeField: 'startTime,endTime',
                component: () => import('@/components/org/datePicker/datePicker.vue'),
                dateType: 'daterange',
                isMul: false,
                isMust: false
              }

            ],
      formField: {
        planMonth: '',
        planWeek: '',
        planStatus: '',
        startTime: '',
        endTime: '',
        carSeriesId: '',
        carConfigId: '',
        optionalPagId: '',
        carColorId: '',
        carIncolorId: ''
      },
      selectionList: [],
      // 动态组件-按钮
      dynamicButtons: this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].tableButtons &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].tableButtons.length > 0
        ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode].tableButtons
        : [
          {
            compKey: 'comKey11',
            type: 'text',
            size: 'small',
            text: '导入模板下载',
            name: '',
            position: 'right',
            clickEvent: () =>
              this.downloadM(
                api.importHqWeekSalePlanDown.APIUrl,
                '总部周计划模板.xlsx',
                { dataType: 'excel' }
              )
          },
          {
            compKey: 'comKey1',
            type: 'primary',
            size: 'small',
            name: 'search',
            position: 'right',
            clickEvent: () => this.queryTable(),
            text: '查询'
          },
          {
            compKey: 'comKey0',
            type: '',
            size: 'small',
            name: 'reset',
            position: 'right',
            clickEvent: () => this.reset(),
            text: '重置'
          },
          {
            compKey: 'comKey6',
            type: '',
            size: 'small',
            name: '',
            position: 'left',
            clickEvent: () => this.add(),
            text: '计划制定'
          },
          {
            compKey: 'comKey10',
            type: '',
            size: 'small',
            name: 'importTemplate',
            position: 'upload',
            // clickEvent: () => this.importtemp(),
            text: '导入'
          },
          {
            compKey: 'comKey2',
            type: '',
            size: 'small',
            name: '',
            position: 'left',
            disabled: true,
            clickEvent: () => this.splitSend('send'),
            text: '拆分发送'
          },
          {
            compKey: 'comKey4',
            type: '',
            size: 'small',
            name: '',
            position: 'left',
            disabled: true,
            clickEvent: () => this.splitSend('noSend'),
            text: '不拆分发送'
          },
          {
            compKey: 'comKey3',
            type: '',
            size: 'small',
            name: '',
            position: 'left',
            disabled: true,
            clickEvent: () => this.delData(),
            text: '删除'
          },
          {
            compKey: 'comKey5',
            type: '',
            size: 'small',
            name: 'export',
            position: 'left',
            clickEvent: () => this.export(),
            text: '导出'
          }
        ],
      // 动态组件-表格网格列
      dynamicTableCols: this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].tableCols.length > 0
        ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode].tableCols
        : [
          {
            prop: 'releaseId',
            label: '主键ID',
            hidden: true,
            alwaysHidden: true
          },
          {
            prop: 'updateControlId',
            label: '并发控制ID',
            hidden: true,
            alwaysHidden: true
          },
          {
            label: '操作',
            minWidth: 180,
            fixed: true,
            isComponent: true,
            comps: [
              {
                compKey: 'propKey1',
                labelName: '编辑',
                component: () => import('@/components/org/linkButton'),
                // component: () => import('@/components/org/datePicker/datePicker.vue'),
                rowFileds: 'show:planStatus-1|8',
                clickEvent: (index) => this.edit(index)
              }
            ]
          },
          {
            prop: 'planStatusCode',
            label: '计划状态'
          },

          {
            prop: 'ttCode',
            label: '22位码',
            width: 180
          },
          {
            prop: 'planMonth',
            label: '计划月份'
          },
          {
            prop: 'planWeek',
            label: '计划周度'
          },
          {
            prop: 'planNum',
            label: '数量'
          },
          {
            prop: 'carSeriesCode',
            label: '车系编码'
          },
          {
            prop: 'carSeriesCn',
            label: '车系名称'
          },
          {
            prop: 'carConfigCode',
            label: '基础车型编码',
            width: 120
          },
          {
            prop: 'carConfigCn',
            label: '基础车型名称',
            width: 110
          },
          {
            prop: 'optionalPagCode',
            label: '选装包编码'
          },
          {
            prop: 'optionalPagName',
            label: '选装包名称'
          },
          {
            prop: 'carColorCode',
            label: '车身颜色编码'
          },
          {
            prop: 'carColorName',
            label: '车身颜色名称'
          },
          {
            prop: 'carIncolorCode',
            label: '内饰颜色编码'
          },
          {
            prop: 'carIncolorName',
            label: '内饰颜色名称'
          },
          {
            prop: 'hostLimitState',
            label: '限制类型'
          },
          {
            prop: 'limitEasonRemark',
            label: '备注'
          },
          {
            prop: 'creator',
            label: '制作人'
          },
          {
            prop: 'createdDate',
            label: '制作时间'
          },
          {
            prop: 'sendTime',
            label: '周计划发送时间'
          }

        ],
      // 单表格模版页面组件回调事件
      callbackObj: {
        // 当选择项发生变化时会触发该事件（多选时）
        onCheckSelectChange: (selection) => {
          this.selectList = selection.map((item) => {
            return item.updateControlId
          })
          this.monthPlanId = selection.map((item) => {
            return item.monthPlanId
          })
          this.planStatus = selection.map((item) => {
            return item.planStatus
          })
          // const genValArray = (array) => (attr) => array.map(item => item[attr])
          // this.list = genValArray(selection)
          this.selectionList = selection
          this.list = this.selectionList.reduce((pre, cur) => {
            pre.push({
              monthPlanId: cur.monthPlanId,
              hostLimitState: cur.hostLimitState,
              limitEasonRemark: cur.limitEasonRemark,
              updateControlId: cur.updateControlId,
              planStatus: cur.planStatus,
              planMonth: cur.planMonth,
              planWeek: cur.planWeek,
              carSerId: cur.carSerId,
              carConfigId: cur.carConfigId,
              carOptionalpagId: cur.carOptionalpagId,
              carColorId: cur.carColorId,
              carIncolorId: cur.carIncolorId,
              ttCode: cur.ttCode,
              planNum: cur.planNum
            })
            return pre
          }, [])
          this.handleSelectionChange(selection)
        },
        onQueryReturn: response => {
          this.$requestAPI({
            apiUrl: api.queryHqWeekSum.APIUrl,
            variables: { ...this.formField }
          }).then(res => {
            this.totalnum = res.rows[0].planNums
          }).catch(err => {
            console.log(err)
          })
          const data = response.rows.map(o => o['infoCode'])
          data.forEach(item => {
            this.codeList.push(item)
          })
        }
      }
    }
  },
  watch: {
    'formField.planMonth': {
      handler(val) {
        if (val) {
          this.formField.planWeek = ''
          var thisMonth = val + '-01'
          this.getweekByplan(thisMonth)
        } else {
          this.getPlanWeek()
        }
      }
    }
  },
  mounted() {
    // 列表查询
    this.getPlanWeek()
    this.queryTable(1)
  },
  methods: {
    autoClose() {
      this.switchPopupsVisible = false
    },
    close1(type) {
      this.showdia = false
      if (type === '1') {
        this.queryTable(1)
      }
    },
    // 导入
    downloadM(url, filename, variable) {
      this.$requestAPI({
        apiUrl: url || api.headquartersExport.APIUrl,
        variables: variable || { ...this.formField, dataType: 'excel' }
      }).then(res => {
        this.$utils.downloadFile(res, filename)
      }).catch(err => {
        console.log(err)
      })
    },
    // 新增
    add() {
      this.dialogStatus = 'weekPlan'
      this.popstate = 'add'
      this.curPopupsVisible = true
    },
    // 计划周度
    getPlanWeek() {
      const optionList = []
      // const options = this.coms[0].data[2].options
      for (let i = 1; i < 53; i++) {
        const num = i
        optionList.push({
          planWeek: `W${num}`,
          planWeekText: `W${num}`
        })
      }
      this.tableComponents[6].options = optionList
    },
    // 获取计划月份周度
    getweekByplan(planMonth) {
      this.$requestAPI({
        apiUrl: api.weekPlan.APIUrl,
        variables: {
          planMonth: planMonth
        }
      }).then(res => {
        if (res.result === '1') {
          const optionList = []
          var arr = res.rows
          arr.forEach(item => {
            optionList.push({
              planWeek: item.PLAN_WEEK,
              planWeekText: item.PLAN_WEEK
            })
          })
          this.tableComponents[6].options = optionList
        } else {
          this.$message(res.msg)
        }
      })
    },
    rp(n) {
      const cnum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十']
      var s = ''
      n = '' + n // 数字转为字符串
      for (var i = 0; i < n.length; i++) {
        s += cnum[parseInt(n.charAt(i))]
      }
      if (s.length === 2) { // 两位数的时候
        // 如果个位数是0的时候，令改成十
        if (s.charAt(1) === cnum[0]) {
          s = s.charAt(0) + '十'
          // 如果是一十改成十
          if (s === cnum[1] + cnum[10]) {
            s = cnum[10]
          }
        } else if (s.charAt(0) === cnum[1]) {
          // 如果十位数是一的话改成十
          s = cnum[10] + s.charAt(1)
        } else if (s.charAt(0) === cnum[2]) {
          // 如果十位数是二的话改成二十
          s = cnum[2] + cnum[10] + s.charAt(1)
        } else if (s.charAt(0) === cnum[3]) {
          // 如果十位数是三的话改成三十
          s = cnum[3] + cnum[10] + s.charAt(1)
        } else if (s.charAt(0) === cnum[4]) {
          // 如果十位数是四的话改成四十
          s = cnum[4] + cnum[10] + s.charAt(1)
        } else if (s.charAt(0) === cnum[5]) {
          // 如果十位数是五的话改成五十
          s = cnum[5] + cnum[10] + s.charAt(1)
        }
      }
      return s
    },
    // 编辑
    edit(idx) {
      this.rowData = this.$refs['multipleTable'].list[idx]
      this.showdia = true
    },
    export() {
      exportExcel(this.formField,
        api.confirmWeekPlanExport.APIUrl,
        'exportStoreMonthSalePlan', '总部周计划制定')
    },
    // 拆分发送
    sendsave(urgent) {
      this.$confirm(urgent === '1' ? '确定要拆分发送紧急订单插单吗?' : '确定要拆分发送普通销售计划吗?', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$requestAPI({
          apiUrl: api.confirmWeekPlan.APIUrl,
          variables: {
            urgent: urgent,
            infoList: this.selectionList
          }
        }).then(res => {
          if (res.result === '1') {
            this.$message(res.msg)
            this.autoClose()
            this.queryTable(1)
          } else {
            res.msg ? this.$message(res.msg) : this.$message('发送失败')
          }
        })
      }).catch(() => {})
    },
    splitSend(type) {
      if (type === 'send') {
        this.switchPopupsVisible = true
      } else {
        this.$confirm('确定要不拆分发送吗?', '提示', {
          confirmButtonText: '确认',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$requestAPI({
            apiUrl: api.noConfirmPlan.APIUrl,
            variables: {
              infoList: this.selectionList
            }
          }).then(res => {
            if (res.result === '1') {
              this.$message(res.msg)
              this.queryTable(1)
            } else {
              res.msg ? this.$message(res.msg) : this.$message('发送失败')
            }
          })
        }).catch(() => {})
      }
    },
    // 自动生成codeField
    genUtil: (array) => (attr) => array.reduce((p, c) => { p[c[attr]] = ''; return p }, {}),
    // 保存 或新增 后会调用此方法
    popClose(type) {
      this.showdia = false
      if (type === 1) {
        this.queryTable(1)
      }
    },
    // 当选择项发生变化时会触发该事件
    handleSelectionChange(selection) {
      const btns = this.dynamicButtons.filter(o => o.disabled !== undefined)
      if (btns.length > 0) {
        const isCheck = selection && selection.length > 0
        if (isCheck) {
          const del = selection.every((item) => {
            return item.planStatus === '8' || item.planStatus === '1'
          })
          if (del) {
            btns[2].disabled = !del
          } else {
            btns[2].disabled = true
          }
          const send = selection.every((item) => {
            return item.planStatus === '1' || item.planStatus === '3' || item.planStatus === '8'
          })
          if (send) {
            btns[0].disabled = !send
          } else {
            btns[0].disabled = true
          }
          const noSend = selection.every((item) => {
            return item.planStatus === '1' || item.planStatus === '8'
          })
          if (noSend) {
            btns[1].disabled = !noSend
          } else {
            btns[1].disabled = true
          }
        } else {
          btns[0].disabled = true
          btns[1].disabled = true
          btns[2].disabled = true
        }
      }
    },

    hiddenColData(data) {
      if (data && data.length > 0) {
        this.refreshTableKey += 1
        this.dynamicTableCols = data
      }
    },
    selectRowsData(rowdata) {

    },

    // 查看附件
    checkFile(index, type) {
      // location.href = process.env.VUE_APP_BASE_API + this.$refs['multipleTable'].list[index].downloadUrl
      window.open(this.$refs['multipleTable'].list[index][type])
    },

    // 删除按钮单条删除
    delOneData(row) {
      const data = [this.$refs['multipleTable'].list[row]]
      this.delData(data)
    },

    // 数据批量删除
    delSeleteData() {
      const data = this.$refs['multipleTable'].$refs['multipleTable'].selection
      this.delData(data)
    },
    handleChange(params) {
      // const url = api.headquartersImport.APIUrl
      // this.$requestImport(url, params, (response) => {
      //   this.uploadSuccess(response)
      // }, '?token=' + this.$store.getters.token)
    },
    // 上传返回结果处理
    uploadSuccess(response) {
      if (response.result === '1' && response.msg !== '') {
        this.$confirm('<p style="height:350px;overflow:auto">' + response.msg + '</p>', '导入结果', {
          dangerouslyUseHTMLString: true,
          showCancelButton: false,
          showClose: false,
          closeOnClickModal: false,
          closeOnPressEscape: false,
          confirmButtonText: '确定',
          type: 'warning'
        }).then(() => {
          this.$refs['multipleTable'].queryTable(1)
        })
      } else if (response.result === '0') {
        this.$message({ type: 'warning', message: response.msg })
        // this.$refs.searchBtns.$refs.upload[0].clearFiles()
      } else {
        this.$alert(`文件导入失败${response.msg}`, '提示', {
          confirmButtonText: '确定',
          type: 'warning'
        })
      }
    },
    // 文件改变
    handFileListChange(params) {
      this.attachHandleChange(params)
    },
    // 上传
    attachHandleChange(param) {
      const loading = this.$loading({
        text: '正在导入'
      })
      const that = this
      const url = api.importHqWeekSalePlan.APIUrl
      that
        .$requestUpload(url, param)
        .then((response) => {
          loading.close()
          this.uploadSuccess(response)
        })
        .catch((err) => {
          loading.close()
          that.modeCode = ''
          console.info(err)
        })
    },

    // 文件格式过滤
    beforeAvatarUpload(file) {
      const extension = file.name.split('.')[1] === 'xls'
      const extension2 = file.name.split('.')[1] === 'xlsx'
      if (!extension && !extension2) {
        this.$alert('上传文件只能为Excel文件', '提示', {
          confirmButtonText: '确定',
          type: 'warning'
        })
      }
      return extension || extension2
    },
    beforeRemove(file, fileList) {
      // console.log(file, fileList)
    },
    handleExceed(file, fileList) {

    },
    // 删除
    delData(selectData) {
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$requestAPI({
          apiUrl: api.confirmWeekPlanDelete.APIUrl,
          variables: { updateControlId: this.selectList, monthPlanId: this.monthPlanId, planStatus: this.planStatus }
        }).then(res => {
          this.$message(res.msg)
          this.queryTable(1)
        })
      }).catch(() => {})
    }
    // getSelectable(data) {
    //   if (data.planStatusCode === '已发送') {
    //     return true
    //   }
    //   return false
    // }
  }
}
</script>

